package com.dlc.longweisheng.chongdianxian;

import android.app.Application;
import android.os.Handler;
import android.os.Looper;

import com.aplus.kira.kiralibrary.tools.UsualTools;
import com.dlc.longweisheng.chongdianxian.pub.Constant;
import com.dlc.longweisheng.chongdianxian.pub.net.Urls;
import com.dlc.longweisheng.chongdianxian.util.Inject;
import com.hoho.android.usbserial.util.LogPlus;
import com.licheedev.adaptscreen.AdaptScreenEx;

import cn.dlc.commonlibrary.okgo.OkGoWrapper;
import cn.dlc.commonlibrary.utils.PrefUtil;
import okhttp3.OkHttpClient;


public class App extends Application {

    private static App application;
    private static Handler mainHandler;

    public static App getInstance() {
        return application;
    }

    @Override
    public void onCreate() {
        application = this;
        UsualTools.isShowPrintMsg = true;
        AdaptScreenEx.init(this);
        PrefUtil.init(this);
        OkGoWrapper.initOkGo(this, new OkHttpClient());
        Urls.BASE_URL = /*"http://" + */PrefUtil.getDefault().getString("host", Constant.DEFAULT_HOST);
        initLog();
        super.onCreate();
    }

    private void initLog() {
        LogPlus.setDebug(true, "charger");
    }

    public Handler getMainHandler() {
        if (mainHandler == null) {
            mainHandler = new Handler(Looper.getMainLooper());
            mainHandler.post(() -> Inject.getInstance().work());
        }
        return mainHandler;
    }
}
